package sort.on2;

/**
 * 选择法排序：从未排序元素中选出最小的与前面的交换
 * 不稳定、原地排序
 *
 * @author yeyangtao created at 16:18 2020/9/25
 */
public class SelectionSort {
    public static void selectionSort(int[] a) {
        int size = a.length;
        for (int i = 0; i < size; i++) {
            int min = i;
            for (int j = i + 1; j < size; j++) {
                if (a[j] < a[min]) min = j;
            }
            //交换
            if (min != i) {
                int temp = a[min];
                a[min] = a[i];
                a[i] = temp;
            }
        }
    }
}
